package com.ziven.common.widget.value;

import android.view.View;

import androidx.annotation.DimenRes;
import androidx.annotation.NonNull;

import com.ziven.common.widget.WidgetUtils;
import com.ziven.easygo.util.ResourceUtils;
import com.ziven.easygo.util.ViewHelper;

/**
 * @author Ziven
 */
public final class DimenValue extends Value {

    public static final int START = 0;
    public static final int TOP = 1;
    public static final int END = 2;
    public static final int BOTTOM = 3;

    public static DimenValue topDimenId(@DimenRes int dimenId) {
        return dimenId(dimenId, TOP);
    }

    public static DimenValue topSize(@NonNull String dp) {
        return size(dp, TOP);
    }

    public static DimenValue topSize(int size) {
        return size(size, TOP);
    }

    public static DimenValue bottomDimenId(@DimenRes int dimenId) {
        return dimenId(dimenId, BOTTOM);
    }

    public static DimenValue bottomSize(@NonNull String dp) {
        return size(dp, BOTTOM);
    }

    public static DimenValue bottomSize(int size) {
        return size(size, BOTTOM);
    }

    public static DimenValue startDimenId(@DimenRes int dimenId) {
        return dimenId(dimenId, START);
    }

    public static DimenValue startSize(@NonNull String dp) {
        return size(dp, START);
    }

    public static DimenValue startSize(int size) {
        return size(size, START);
    }

    public static DimenValue endDimenId(@DimenRes int dimenId) {
        return dimenId(dimenId, END);
    }

    public static DimenValue endSize(@NonNull String dp) {
        return size(dp, END);
    }

    public static DimenValue endSize(int size) {
        return size(size, END);
    }

    public static DimenValue dimenId(@DimenRes int dimenId, int direction) {
        return size(ResourceUtils.getDimen(dimenId), direction);
    }

    public static DimenValue size(@NonNull String dp, int direction) {
        return size(WidgetUtils.dimenInt(dp), direction);
    }

    public static DimenValue size(int size, int direction) {
        return new DimenValue().accept(my -> {
            my.resId = direction;
            my.value = size;
        });
    }

    public static DimenValue dimenId(@DimenRes int dimenId) {
        return size(ResourceUtils.getDimen(dimenId));
    }

    public static DimenValue size(@NonNull String dp) {
        return size(WidgetUtils.dimenInt(dp));
    }

    public static DimenValue size(int size) {
        return new DimenValue().accept(my -> my.value = size);
    }

    private DimenValue() {}

    public int value() {
        return value(0);
    }

    public int value(int def) {
        return value instanceof Integer ? (int) value : def;
    }

    public int direction() {
        return resId;
    }

    public boolean isTop() {
        return resId == TOP;
    }

    public boolean isBottom() {
        return resId == BOTTOM;
    }

    public boolean isStart() {
        return resId == START;
    }

    public boolean isEnd() {
        return resId == END;
    }

    @Override
    protected void takeEffect(@NonNull ViewHelper<? extends View> helper) {
        //Do nothing
    }
}
